#include <memory.h>
#include <assert.h>

#include "aba_utils.h"
#include "aba_memory.h"
#include "code.h"

/* TODO define specific types for code and memory */
int load_code(char code[], char memory[], size_t start_addr, size_t size)
{
	int ret;
	assert(code && memory);

	if (start_addr + size >= MAXMEM) {
		LOGD("F", "memory limit exceeded!\n");
		return -1;	/* TODO -EINVAL invalid parameter? */
	}

	ret = memcpy(memory+start_addr, code, size);
	if (ret) 
		LOGD("D", "memcpy() returns %d\n", ret);
	LOGV("code loaded\n");
	return ret;
}
